package com.yx.changdao.generate.utils;

import java.util.HashMap;

/**
 * @Description: <br/>
 * 数据库字段转Java字段
 * <p>
 * <br/>
 * @Auther: zhangqi
 * @create 2019/11/23 12:15
 */
public class ColumnType {

    private static HashMap<String, String> typeMap = new HashMap<String, String>();

    public static final String JAVA_TYPE_STRING = "String";
    public static final String JAVA_TYPE_INTEGER = "Integer";
    public static final String JAVA_TYPE_LONG = "Long";
    public static final String JAVA_TYPE_TIMESTAMP = "Date";
    public static final String JAVA_TYPE_FLOAT = "Float";
    public static final String JAVA_TYPE_DOUBLE = "Double";
    public static final String JAVA_TYPE_BIGDECIMAL = "BigDecimal";

    static {
        typeMap.put("VARCHAR", JAVA_TYPE_STRING);
        typeMap.put("CHAR", JAVA_TYPE_STRING);
        typeMap.put("INT", JAVA_TYPE_INTEGER);
        typeMap.put("INT UNSIGNED", JAVA_TYPE_INTEGER);
        typeMap.put("TINYINT", JAVA_TYPE_INTEGER);
        typeMap.put("MEDIUMINT", JAVA_TYPE_INTEGER);
        typeMap.put("BIGINT", JAVA_TYPE_LONG);
        typeMap.put("DATETIME", JAVA_TYPE_TIMESTAMP);
        typeMap.put("DATE", JAVA_TYPE_TIMESTAMP);
        typeMap.put("FLOAT", JAVA_TYPE_FLOAT);
        typeMap.put("DOUBLE", JAVA_TYPE_DOUBLE);
        typeMap.put("DECIMAL", JAVA_TYPE_BIGDECIMAL);
    }

    public static String getJavaTypeOf(String data_type) {
        if (typeMap.containsKey(data_type)) {
            return typeMap.get(data_type);
        }
        return JAVA_TYPE_STRING;
    }
}
